<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class typeController extends Controller
{  
	//属性添加表单
    public function add()
    {
    	$data = DB::table('goods') -> get();
    	return view('admin.type.add',['data' => $data]);
    }
    //属性添加执行
    public function insert(Request $request)
    { 
       $data = $request -> except('_token');
       //dd($data);
       $res = DB::table('type') -> insert($data);
       if($res)
       {
       	  return redirect('/admin/type/menu',['info' => '添加陈功']);
       }else{
       	  return back() -> with(['info' => '添加失败']);
       }

    }
    //属性列表
    public function menu(Request $request)
    {   
         $num = $request -> input('num',10);
    	$data = DB::table('type as t')
    	     -> select('t.*','g.name','g.price','g.img')
    	     -> leftjoin('goods as g','t.gid','=','g.id')
    	     -> where(function($query)use($request){
                $query->where('g.name','like','%'.$request->input('keyword').'%');
     	     	
    	     })
    	     -> paginate($num);
    	   //dd($data);  
    	 return view('admin.type.menu',['data' => $data]);
    }
    //属性修改表单
    public function alter($id)
    {
    	$data = DB::table('type as t') 
    	     -> select('t.*','g.name')
    	     -> leftjoin('goods as g','t.gid','=','g.id')
    	     -> where('t.id',$id) 
    	     -> first();
    	//dd($data);
    	return view('admin.type.alter',['data' => $data]);
    }            	    
     	 

}
